package designMode.single;


/**
 * @Author 肖地洋
 * @Date 2022/8/12 15:44
 */
public class DoubleCheckSingle {

    private static DoubleCheckSingle INTANCE;
    private DoubleCheckSingle(){
        System.out.println("DoubleCheckSingle()");
    }

    public static DoubleCheckSingle getInstance(){
        if(INTANCE==null){
            synchronized (DoubleCheckSingle.class){
                if(INTANCE==null){
                    // java1.4之前有指令重排，需要加volatile关键字,但是在高版本的java中进行了优化，所以不需要加
                    INTANCE = new DoubleCheckSingle();
                }
            }
        }
        return INTANCE;
    }

    public static void main(String[] args) {

    }
}
